package Visitor;

import Entities.Advantages.DecreaseBallSpeed;
import Entities.Advantages.DecreaseBarSize;
import Entities.Advantages.IAdvantage;
import Entities.Advantages.IncreaseBallSpeed;
import Entities.Advantages.IncreaseBarSize;
import Entities.Ball;
import Entities.Bar;
import Entities.Boundary;
import Entities.Brick;
import Entities.Drawable;
import Entities.Hinder;

public class BarCollisionVisitor implements IVisitor {

    private Bar bar;

    public BarCollisionVisitor(Bar bar) {
        this.bar = bar;
    }

    @Override
    public Drawable visit(Bar bar) {
        return null;
    }

    @Override
    public Drawable visit(Ball ball) {
        return null;
    }

    @Override
    public Drawable visit(Boundary boundary) {
        return null;
    }

    @Override
    public Drawable visit(IAdvantage advantage) {
        if (bar.getX() - advantage.getWidth() / 2 <= advantage.getX() && advantage.getX() + advantage.getWidth() <= bar.getX() + bar.getWidth() * 2) {
            if (bar.getY() - 1 <= advantage.getY() + advantage.getHeight() && advantage.getY() + advantage.getHeight() <= bar.getY() + 1) {
                return advantage;
            }
        }
        if (bar.getY() <= advantage.getY() + advantage.getHeight()) {
            if (bar.getX() - 2 <= advantage.getX() + advantage.getWidth() && advantage.getX() + advantage.getWidth() <= bar.getX()) {
                return advantage;
            }
            if (bar.getX() + bar.getWidth() <= advantage.getX() && advantage.getX() <= bar.getX() + bar.getWidth() + 2) {
                return advantage;
            }
        }
        return null;
    }

    @Override
    public Drawable visit(Brick brick) {
        return null;
    }

    @Override
    public Drawable visit(Drawable drawable) {
        return null;
    }

    @Override
    public Drawable visit(Hinder hinder) {
        return null;
    }

    @Override
    public Drawable visit(DecreaseBarSize decreaseBarSize) {
        return visit((IAdvantage) decreaseBarSize);
    }

    @Override
    public Drawable visit(IncreaseBarSize increaseBarSize) {
        return visit((IAdvantage) increaseBarSize);
    }

    @Override
    public Drawable visit(DecreaseBallSpeed decreaseBallSpeed) {
        return visit((IAdvantage) decreaseBallSpeed);
    }

    @Override
    public Drawable visit(IncreaseBallSpeed increaseBallSpeed) {
        return visit((IAdvantage) increaseBallSpeed);
    }
}
